package xcmg.device.web.secondAgent;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.secondAgent.SecondAgentService;
import xcmg.device.service.vo.secondAgent.SecondAgentConditionVO;
import xcmg.device.service.vo.secondAgent.SecondAgentVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.SearchCommonVO;

@RestController
@RequestMapping("/secondAgent")
public class SecondAgentController extends BasicController {

	@Autowired
	private SecondAgentService secondAgentService;
	
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "新增二级代理商关系")
    @FastMappingInfo(needLogin = true)
	public ActionResult add(@RequestBody List<SecondAgentVO> secondAgentVOs) throws Exception {
		ErrorCode errorCode = secondAgentService.add(secondAgentVOs, getUserId(), getOrgId());
		return actionResult(errorCode);
	}
    
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @ApiOperation(value = "删除二级代理商关系")
    @FastMappingInfo(needLogin = true)
	public ActionResult delete(String id) {
		ErrorCode errorCode = secondAgentService.delete(id, getUserId());
		return actionResult(errorCode);
	}
    
    @RequestMapping(value = "/delBatch", method = RequestMethod.POST)
    @ApiOperation(value = "批量删除二级代理商关系")
    @FastMappingInfo(needLogin = true)
    public ActionResult delBatch(@RequestBody List<String> ids) {
    	ErrorCode errorCode = secondAgentService.delBatch(ids, getUserId());
    	return actionResult(errorCode);
    }
    
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(value = "二级代理商列表查询")
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestBody SearchCommonVO<SecondAgentConditionVO> condition) throws Exception {
    	return actionValueResult(secondAgentService.list(condition, getOrgId()).getPageInfo());
    }
    
    @RequestMapping(value = "/listOemInfos", method = RequestMethod.GET)
    @ApiOperation(value = "二级代理商查询主机厂")
    @FastMappingInfo(needLogin = true)
    public ActionResult listOemInfos() throws Exception {
    	return actionValueResult(secondAgentService.listOemInfos(getOrgId()));
    }
}
